package com.heima.admin.controller;

import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.admin.service.ChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "频道控制层", tags = "敏感词管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {

    @Autowired
    private ChannelService channelService;

    @ApiOperation("频道查询")
    @PostMapping("/list")
    public ResponseResult query(@RequestBody ChannelDTO channelDTO) {
        return channelService.findByNameAndPage(channelDTO);
    }

    @ApiOperation("频道新增")
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel) {
        return channelService.saveChannel(adChannel);
    }

    @ApiOperation("频道修改")
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel) {
        return channelService.updateChannel(adChannel);
    }

    @ApiOperation("频道删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer id) {
        return channelService.deleteChannel(id);
    }

    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(channelService.getById(id));
    }
}
